package com.ruoyi.permission.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.baoziyi.domain.SerBaoziyiDeviceInfo;
import com.ruoyi.baoziyi.mapper.SerBaoziyiDeviceInfoMapper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.inducePest.domain.device.InduceDeviceInfo;
import com.ruoyi.inducePest.mapper.device.InduceDeviceMapper;
import com.ruoyi.lightkillPest.domain.device.SCDDeviceDao;
import com.ruoyi.lightkillPest.mapper.SCDDeviceMapper;
import com.ruoyi.permission.Dao.*;
import com.ruoyi.permission.domain.*;
import com.ruoyi.permission.mapper.*;
import com.ruoyi.permission.service.PermiService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.traplight.domain.DeviceDao;
import com.ruoyi.traplight.mapper.TrapLightDeviceMapper;
import com.ruoyi.utils.LocationUtil;
import com.ruoyi.xag.domain.IotDeviceInfo;
import com.ruoyi.xag.mapper.DeviceMapper;
import com.ruoyi.ysVideo.domain.MyDeviceName;
import com.ruoyi.ysVideo.mapper.EzvizMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

@Service
public class PermiServiceImpl implements PermiService {
    @Autowired
    private SerUnitPermiMapper unitPermiMapper;
    @Autowired
    private SerBasePermiMapper basePermiMapper;
    @Autowired
    private SerBlockPermiMapper blockPermiMapper;
    @Autowired
    private SerDevicePermiMapper devicePermiMapper;
    @Autowired
    private SerInsectPermiMapper insectPermiMapper;
    @Autowired
    private SerUnitBaseMapper serUnitBaseMapper;
    @Autowired
    private SerUnitFuncMapper serUnitFuncMapper;
    @Autowired
    private SerUnitUserMapper serUnitUserMapper;
    @Autowired
    private SerBaseBlockMapper serBaseBlockMapper;
    @Autowired
    private SerBlockDeviceMapper serBlockDeviceMapper;
    @Autowired
    private SerDeviceInsectMapper serDeviceInsectMapper;
    @Autowired
    private SerFuncPermiMapper serFuncPermiMapper;
    @Autowired
    private TrapLightDeviceMapper trapLightDeviceMapper;
    @Autowired
    private InduceDeviceMapper induceDeviceMapper;
    @Autowired
    private DeviceMapper iotDeviceMapper;
    @Autowired
    private SCDDeviceMapper scdDeviceMapper;
    @Autowired
    private EzvizMapper videoMapper;
    @Autowired
    private SerBaoziyiDeviceInfoMapper baoziyiDeviceMapper;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private SerBaseDeviceMapper serBaseDeviceMapper;

    //获取单位列表
    public List<UnitPermiInfo> selectAllUnitPermi(){
        return unitPermiMapper.selectAllUnitPermi();
    }
    //根据unitId获取用户列表
    public List<UnitPermiUserInfo> selectUserListByUnitId(int id){
        return unitPermiMapper.selectUserListByUnitId(id);
    }

    //根据unitId获取功能列表
    public List<UnitPermiFuncInfo> selectFuncListByUnitId(int id){
        if(id !=0) {
            return unitPermiMapper.selectFuncListByUnitId(id);
        }else {
            List<UnitPermiFuncInfo> resList = new ArrayList<>();
            List<SerFuncPermi> serFuncPermiLst = serFuncPermiMapper.selectAllFuncPermi();
            for(SerFuncPermi serFuncPermi:serFuncPermiLst){
                Integer id1 = serFuncPermi.getId();
                String funcName = serFuncPermi.getFuncName();
                UnitPermiFuncInfo newUnitFunc = new UnitPermiFuncInfo().setFuncId(id1).setFuncName(funcName).setUnitId(id);
                resList.add(newUnitFunc);
            }
            return resList;
        }
    }

    //根据unitId获取基地列表
    public List<UnitPermiBaseInfo> selectBaseListByUnitId(int id){
        return unitPermiMapper.selectBaseListByUnitId(id);
    }

    //根据baseId获取地块列表
    public List<BasePermiBlockInfo> selectBlockListByBaseId(int id){
        return basePermiMapper.selectBlockListByBaseId(id);
    }

    //根据blockId获取设备列表
    public List<BlockPermiDeviceInfo> selectDeviceListByBlockId(int id){
        return blockPermiMapper.selectDeviceListByBlockId(id);
    }

    //添加新单位
    public int insertUnit(SerUnitPermi unitPermi){
        String unitName = unitPermi.getUnitName();
        List<UnitPermiInfo> unitPermiInfos = unitPermiMapper.selectAllUnitPermi();
        for(UnitPermiInfo unitPermiInfo:unitPermiInfos){
            if(unitPermiInfo.getUnitName().equals(unitName) || unitPermiInfo.getUnitName() == null || unitPermiInfo.getUnitName() == ""){
                return -1;
            }
        }
        return unitPermiMapper.insert(unitPermi);
    }

    //添加新设备
    public int insertDevice(SerDevicePermi devicePermi){
        String deviceSerial = devicePermi.getDeviceSerial();
        Integer typeId = devicePermi.getTypeId();
        String nickName = devicePermi.getDeviceName();
        List<SerDevicePermi> devicePermiInfos = devicePermiMapper.selectAllDevicePermi();
        int i = 0;
        int j = 0;
        for(SerDevicePermi devicePermiInfo:devicePermiInfos){
            if(devicePermiInfo.getDeviceSerial().equals(deviceSerial)){
                return -1;
            }
        }
        switch (typeId){
//            添加测报灯表
            case 1:
                break;
//                性诱设备表
            case 2:
                InduceDeviceInfo induceDeviceInfo = new InduceDeviceInfo().setCameraId(deviceSerial).setStatus("在线").setName(nickName);
                i =  devicePermiMapper.insert(devicePermi);
                j = induceDeviceMapper.insertDeviceInfo(induceDeviceInfo);
                break;
//                气象土壤设备表
            case 3:
            case 4:
                IotDeviceInfo iotDeviceInfo = new IotDeviceInfo().setDeviceId(deviceSerial).setDeviceStatus("在线").setDeviceName(nickName);
                i =  devicePermiMapper.insert(devicePermi);
                j = iotDeviceMapper.insertIotDevice(iotDeviceInfo);
                break;
//                杀虫灯设备表
            case 5:
                break;
//                视频监控设备表
            case 6:
                break;
//                孢子仪设备表
            case 7:
                break;
        }
        
        return i + j;
    }
    //为单位添加基地
    public int insertUnitPermiBase(UnitPermiBaseInfo unitBase){

        SerBasePermi serBasePermi = new SerBasePermi().setBaseName(unitBase.getBaseName()).setBaseArea(unitBase.getBaseArea());
        List<SerBasePermi> basePermiInfos = basePermiMapper.selectAllBasePermi();
        //用于判断该基地是否存在  0代表不存在 1代表存在
        int flag = 0;
        for(SerBasePermi basePermiInfo: basePermiInfos){
            if(basePermiInfo.getBaseName().equals(unitBase.getBaseName())){
                flag = 1;
            }
        }
        if(flag == 0) {
            basePermiMapper.insert(serBasePermi);
        }
        Integer baseId = basePermiMapper.selectByBaseName(unitBase.getBaseName()).getId();
        SerUnitBase serUnitBase = new SerUnitBase().setUnitId(unitBase.getUnitId()).setBaseId(baseId);
        int i = serUnitBaseMapper.insert(serUnitBase);
        return i;
    }

    //为单位添加功能模块，
    public int insertUnitPermiFunc(SerUnitFunc unitFunc){
        List<SerFuncPermi> allFuncPermiList = serFuncPermiMapper.selectAllFuncPermi();
        for(SerFuncPermi funcPermi:allFuncPermiList){
            if(funcPermi.getId().intValue() == unitFunc.getFuncId().intValue()){
                return serUnitFuncMapper.insert(unitFunc);
            }
        }
        //如果没有该功能权限
        return -1;
    }

    //为单位添加用户
    public int insertUnitPermiUser(SerUnitUser unitUser){
        List<SysUser> allUserList = userService.selectUserList(new SysUser());
        for(SysUser sysUser:allUserList){
            if(sysUser.getUserId().intValue() == unitUser.getUserId().intValue()){
                return serUnitUserMapper.insert(unitUser);
            }
        }
        //不存在该用户
        return -1;
    }

    //为基地添加地块
    public int insertBasePermiBlock(BasePermiBlockInfo baseBlock){
        SerBlockPermi serBlockPermi = new SerBlockPermi().setBlockName(baseBlock.getBlockName());
        List<SerBlockPermi> blockPermiInfos = blockPermiMapper.selectAllBlockPermi();
        //用于判断是否已经存在该地块  0代表不存在 1代表存在
        int flag = 0;
        for(SerBlockPermi blockPermiInfo: blockPermiInfos){
            if(blockPermiInfo.getBlockName().equals(baseBlock.getBlockName())){
                flag = 1;
            }
        }
        if(flag == 0) {
            blockPermiMapper.insert(serBlockPermi);
        }
        Integer blockId = blockPermiMapper.selectByBlockName(baseBlock.getBlockName()).getId();
        SerBaseBlock serBaseBlock = new SerBaseBlock().setBlockId(blockId).setBaseId(baseBlock.getBaseId());
        int i = serBaseBlockMapper.insert(serBaseBlock);
        return i;
    }

    //为地块添加设备
    public int insertBlockPermiDevice(SerBlockDevice blockDevice){
        return serBlockDeviceMapper.insert(blockDevice);
    }

    //为设备添加虫情权限
    public int insertDevicePermiInsect(SerDeviceInsect deviceInsect){
        List<SerInsectPermi> allInsectPermiList = insectPermiMapper.selectAllInsectPermi();
//        用来判断绑定的虫情权限是否存在  0表示不存在 1表示存在
        int flag=0;
        for(SerInsectPermi insectPermi:allInsectPermiList){
            if(insectPermi.getId().intValue() == deviceInsect.getInsectId().intValue()){
                flag = 1;
            }
        }
        if(flag == 1) {
            return serDeviceInsectMapper.insert(deviceInsect);
        }else {
            return 0;
        }
    }

    //新增虫情
    public int insertInsectPermi(SerInsectPermi insectPermi){
        String name = insectPermi.getName();
        List<SerInsectPermi> insectPermiInfos = insectPermiMapper.selectAllInsectPermi();
        for(SerInsectPermi insectPermiInfo:insectPermiInfos){
            if(insectPermiInfo.getName().equals(name)){
                return -1;
            }
        }
        return insectPermiMapper.insertSelective(insectPermi);
    }

    //删除某单位的基地
    public int deleteUnitPermiBase(Integer baseId){
        return serUnitBaseMapper.deleteByPrimaryKey(baseId);
    }

    //删除某单位的功能模块
    public int deleteUnitPermiFunc(SerUnitFunc unitFunc){
        return serUnitFuncMapper.delete(unitFunc);
    }

    //删除某单位的用户
    public int deleteUnitPermiUser(Integer userId){
        return serUnitUserMapper.deleteByPrimaryKey(userId);
    }

    //删除基地的某地块
    public int deleteBasePermiBlock(Integer blockId){
        return serBaseBlockMapper.deleteByPrimaryKey(blockId);
    }

    //删除地块的某设备
    public int deleteBlockPermiDevice(SerBlockDevice blockDevice){
        return serBlockDeviceMapper.deleteByPrimaryKey(blockDevice);
    }

    /*************************************************************************************/
    //根据单位获取所有设备
    public List<BaseBlockPermiDeviceInfo> selectAllDeviceByUnitId(Integer unitId) {
        List<BaseBlockPermiDeviceInfo> resList = new ArrayList<>();
//        非管理员
        if (unitId != 0) {
            List<UnitPermiBaseInfo> unitPermiBaseInfoList = unitPermiMapper.selectBaseListByUnitId(unitId);
            for (UnitPermiBaseInfo unitPermiBaseInfo : unitPermiBaseInfoList) {
                Integer baseId = unitPermiBaseInfo.getBaseId();
                if(basePermiMapper.selectDeviceListByBaseId(baseId)!=null){
                    List<BasePermiDeviceInfo> basePermiDeviceInfoList = basePermiMapper.selectDeviceListByBaseId(baseId);
                    for(BasePermiDeviceInfo basePermiDeviceInfo:basePermiDeviceInfoList){
                        Integer id = basePermiDeviceInfo.getId();
                        String deviceSerial = basePermiDeviceInfo.getDeviceSerial();
                        String deviceName = basePermiDeviceInfo.getDeviceName();
                        Integer deviceId = basePermiDeviceInfo.getDeviceId();
                        String manualId = basePermiDeviceInfo.getManualId();
                        String deviceType = basePermiDeviceInfo.getDeviceType();
                        Integer typeId = basePermiDeviceInfo.getTypeId();
                        Double longitude = basePermiDeviceInfo.getLongitude();
                        Double latitude = basePermiDeviceInfo.getLatitude();
                        String onlineState = basePermiDeviceInfo.getOnlineState();
                        String area = basePermiDeviceInfo.getArea();
                        Double battery = basePermiDeviceInfo.getBattery();
                        String province = basePermiDeviceInfo.getProvince();
                        BaseBlockPermiDeviceInfo baseBlockPermiDeviceInfo = new BaseBlockPermiDeviceInfo().setId(id).setBaseId(baseId).setDeviceSerial(deviceSerial).setDeviceName(deviceName)
                                .setDeviceId(deviceId).setManualId(manualId).setDeviceType(deviceType).setTypeId(typeId).setLongitude(longitude).setLatitude(latitude).setOnlineState(onlineState)
                                .setArea(area).setBattery(battery).setProvince(province);
                        resList.add(baseBlockPermiDeviceInfo);
                    }
                    break;
                }
                List<BasePermiBlockInfo> basePermiBlockInfoList = basePermiMapper.selectBlockListByBaseId(baseId);
                for (BasePermiBlockInfo basePermiBlockInfo : basePermiBlockInfoList) {
                    Integer blockId = basePermiBlockInfo.getBlockId();
                    List<BlockPermiDeviceInfo> blockPermiDeviceInfoList = blockPermiMapper.selectDeviceListByBlockId(blockId);
                    for(BlockPermiDeviceInfo blockPermiDeviceInfo:blockPermiDeviceInfoList){
                        Integer id = blockPermiDeviceInfo.getId();
                        String deviceSerial = blockPermiDeviceInfo.getDeviceSerial();
                        String deviceName = blockPermiDeviceInfo.getDeviceName();
                        Integer deviceId = blockPermiDeviceInfo.getDeviceId();
                        String manualId = blockPermiDeviceInfo.getManualId();
                        String deviceType = blockPermiDeviceInfo.getDeviceType();
                        Integer typeId = blockPermiDeviceInfo.getTypeId();
                        Double longitude = blockPermiDeviceInfo.getLongitude();
                        Double latitude = blockPermiDeviceInfo.getLatitude();
                        String onlineState = blockPermiDeviceInfo.getOnlineState();
                        String area = blockPermiDeviceInfo.getArea();
                        Double battery = blockPermiDeviceInfo.getBattery();
                        String province = blockPermiDeviceInfo.getProvince();
                        BaseBlockPermiDeviceInfo baseBlockPermiDeviceInfo = new BaseBlockPermiDeviceInfo().setId(id).setBlockId(blockId).setDeviceSerial(deviceSerial).setDeviceName(deviceName)
                                .setDeviceId(deviceId).setManualId(manualId).setDeviceType(deviceType).setTypeId(typeId).setLongitude(longitude).setLatitude(latitude).setOnlineState(onlineState)
                                .setArea(area).setBattery(battery).setProvince(province);
                        resList.add(baseBlockPermiDeviceInfo);
                    }
                }
            }
        }else{
            List<SerDevicePermi> serDevicePermiList = devicePermiMapper.selectAllDevicePermi();
            for(SerDevicePermi serDevicePermi:serDevicePermiList){

                Integer id = serDevicePermi.getId();
                Integer blockId = null;
                Integer baseId = null;
                if(serBaseDeviceMapper.selectByPrimaryKey(id)!=null){
                    baseId = serBaseDeviceMapper.selectByPrimaryKey(id).getBaseId();
                }
                else if(serBlockDeviceMapper.selectByPrimaryKey(id)!=null){
                    blockId = serBlockDeviceMapper.selectByPrimaryKey(id).getBlockId();
                }

                String deviceSerial = serDevicePermi.getDeviceSerial();
                String deviceName = serDevicePermi.getDeviceName();
                String deviceType = serDevicePermi.getDeviceType();
                Integer typeId = serDevicePermi.getTypeId();
                Integer deviceNo = serDevicePermi.getDeviceNo();
                String manualId = serDevicePermi.getManualId();
                Double longitude = serDevicePermi.getLongitude();
                Double latitude = serDevicePermi.getLatitude();
                String onlineState = serDevicePermi.getOnlineState();
                String area = serDevicePermi.getArea();
                Double battery = serDevicePermi.getBattery();
                String province = serDevicePermi.getProvince();
                BaseBlockPermiDeviceInfo newBaseBlockDevice = new BaseBlockPermiDeviceInfo().setDeviceSerial(deviceSerial).setDeviceName(deviceName).setDeviceType(deviceType).setId(id)
                        .setTypeId(typeId).setDeviceId(deviceNo).setManualId(manualId).setLongitude(longitude).setLatitude(latitude).setOnlineState(onlineState).setArea(area).setBattery(battery)
                        .setProvince(province).setBlockId(blockId).setBaseId(baseId);
                resList.add(newBaseBlockDevice);
            }
        }
        return resList;
    }

    /**
     * 根据设备id获取所有的虫情权限,如果输入deviceId为0，则默认为管理员，返回所有虫情权限
     * @param deviceIds
     * @return
     */
    public HashMap selectInsectPermiByDeviceId(String deviceIds){
        HashMap<Integer,List<String>> resMap = new HashMap<>();
        if(deviceIds!="") {
            String[] item = deviceIds.split(",");
            List<String> deviceIdList = new ArrayList<>(Arrays.asList(item));
            for(String deviceId:deviceIdList) {
                List<String> resLst = new ArrayList<>();
                List<DevicePermiInsectInfo> devicePermiInsectInfoLst = devicePermiMapper.selectInsectListByDeviceId(Integer.parseInt(deviceId));
                for (DevicePermiInsectInfo devicePermiInsectInfo : devicePermiInsectInfoLst) {
                    String ret = devicePermiInsectInfo.getRet();
                    resLst.add(ret);
                }
                resMap.put(Integer.valueOf(deviceId),resLst);
            }
        }else{
            List<SerInsectPermi> insectPermiLst = insectPermiMapper.selectAllInsectPermi();
            List<String> resLst = new ArrayList<>();
            for(SerInsectPermi insectPermi:insectPermiLst){
                String ret = insectPermi.getRet();
                resLst.add(ret);
            }
            resMap.put(0,resLst);
        }
        return resMap;
    }

//    public List<DevicePermiInsectInfo> selectAllInsectByUnitId(Integer unitId){
//        List<DevicePermiInsectInfo> resLst = new ArrayList<>();
//        if(unitId !=0){
//            List<BlockPermiDeviceInfo> blockPermiDeviceInfoLst = selectAllDeviceByUnitId(unitId);
//            for(BlockPermiDeviceInfo blockPermiDeviceInfo:blockPermiDeviceInfoLst){
//                Integer deviceId = blockPermiDeviceInfo.getDeviceId();
//                List<DevicePermiInsectInfo> devicePermiInsectInfos = devicePermiMapper.selectInsectListByDeviceId(deviceId);
//
//            }
//        }
//    }

    @Override
    public int updateUnitInfo(SerUnitPermi unitPermi){
        return unitPermiMapper.updateByPrimaryKeySelective(unitPermi);
    }
    @Override
    public int updateBaseInfo(SerBasePermi basePermi){
        return basePermiMapper.updateByPrimaryKeySelective(basePermi);
    }
    @Override
    public int updateBlockInfo(SerBlockPermi blockPermi){
        return blockPermiMapper.updateByPrimaryKeySelective(blockPermi);
    }

    /**
     * 更新设备表
     * @param devicePermi（必填：deviceSerial,typeId）
     * @return
     */
    @Override
    public int updateDeviceInfo(SerDevicePermi devicePermi){
        String nickName = null;
        String manualId = null;
        Double longitude = null;
        Double latitude = null;
        String onlineState = null;
        String province = null;
//        只能根据经纬度转换不能手动输入
        String area = null;
        Double battery = null;
        String location = null;
        if(devicePermi.getDeviceName()!=null && devicePermi.getDeviceName() !=""){
            nickName = devicePermi.getDeviceName();
        }
        if(devicePermi.getManualId()!=null && devicePermi.getManualId()!=""){
            manualId = devicePermi.getManualId();
        }
        if(devicePermi.getLongitude()!=null && devicePermi.getLatitude()!=null){
            longitude = devicePermi.getLongitude();
            latitude = devicePermi.getLatitude();
            try {
                JSONObject locationObject = LocationUtil.reverseGeoCode(longitude,latitude);
                area = locationObject.getString("city") + locationObject.getString("district");
                province = locationObject.getString("province");
                location = locationObject.getString("formattedAddress");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        if(devicePermi.getOnlineState()!=null && devicePermi.getOnlineState()!=""){
            onlineState = devicePermi.getOnlineState();
        }
        if(devicePermi.getBattery() !=null){
            battery = devicePermi.getBattery();
        }
        String deviceSerial = devicePermi.getDeviceSerial();
        Integer typeId = devicePermi.getTypeId();
        Integer deviceNo = devicePermi.getDeviceNo();
        devicePermi.setArea(area).setProvince(province);
        int i = devicePermiMapper.updateByPrimaryKeySelective(devicePermi);
        int j = 0;
        switch (typeId)
        {
//            更新测报灯表
            case 1:
                DeviceDao deviceDao = new DeviceDao().setDeviceName(deviceSerial).setDeviceStatus(onlineState).setNickName(nickName)
                        .setArea(area);
                j = trapLightDeviceMapper.updateDeviceSelective(deviceDao);
                break;
//                更新性诱表
            case 2:
                InduceDeviceInfo induceDeviceInfo = new InduceDeviceInfo().setId(deviceNo).setName(nickName).setManualId(manualId)
                                .setLongitude(longitude).setLatitude(latitude).setLocation(location);
                j = induceDeviceMapper.updateDeviceInfoById(induceDeviceInfo);
                break;
            case 3:
            case 4:
                IotDeviceInfo iotDeviceInfo = new IotDeviceInfo().setDeviceId(deviceSerial).setDeviceName(nickName).setDeviceStatus(onlineState)
                        .setLongitude(longitude).setLatitude(latitude).setLocation(location);
                j = iotDeviceMapper.updateDevice(iotDeviceInfo);
                break;
            case 5:
                SCDDeviceDao scdDeviceDao = new SCDDeviceDao().setDeviceId(deviceSerial).setDeviceStatus(onlineState).setNickName(nickName).setManualId(manualId)
                        .setLongitude(longitude).setLatitude(latitude).setBattery(battery).setLocation(location);
                j = scdDeviceMapper.updateSCDDeviceInfo(scdDeviceDao);
                break;
            case 6:
                MyDeviceName myDeviceName = new MyDeviceName().setDeviceSerial(deviceSerial).setRemark(nickName);
                j = videoMapper.updateRemarkName(myDeviceName);
                break;
            case 7:
                SerBaoziyiDeviceInfo baoziyiDeviceInfo = new SerBaoziyiDeviceInfo().setDeviceId(deviceSerial).setNickName(nickName).setManualId(manualId).setLongitude(longitude).setLatitude(latitude).setLocation(location);
                j = baoziyiDeviceMapper.updateByPrimaryKeySelective(baoziyiDeviceInfo);
                break;
        }
        return i+j;
    }
    /**
     * 根据设备id获取虫情权限
     * @param deviceId
     * @return
     */
    @Override
    public DevicePermiInsectList selectInsectByDeviceId(Integer deviceId){
        List<DevicePermiInsectInfo> devicePermiInsectInfoList = devicePermiMapper.selectInsectListByDeviceId(deviceId);
//        返回结果
        DevicePermiInsectList devicePermiInsectList = new DevicePermiInsectList().setDeviceId(deviceId);
        List<SerInsectPermi> serInsectPermiList = new ArrayList<>();
        for(DevicePermiInsectInfo devicePermiInsectInfo:devicePermiInsectInfoList){
//            昆虫id
            Integer insectId = devicePermiInsectInfo.getId();
//            昆虫代号
            String ret = devicePermiInsectInfo.getRet();
//            昆虫名
            String name = devicePermiInsectInfo.getName();
//            昆虫属于几类害虫
            String inves = devicePermiInsectInfo.getInves();
            SerInsectPermi newInsectPermi = new SerInsectPermi().setId(insectId).setName(name).setRet(ret).setInves(inves);
            serInsectPermiList.add(newInsectPermi);
        }
        devicePermiInsectList.setInsectPermiList(serInsectPermiList);
        return devicePermiInsectList;
    }

    // 根据设备id修改球机别名
    public int updateEzvizDeviceNameById(EzvizDeviceName ezvizDeviceName){return devicePermiMapper.updateEzvizDeviceNameById(ezvizDeviceName);}

}
